<template>
  <div class="mr-mr-midSearch">

  </div>
</template>
<script>
import { partFinSearch,bufferBoxOut,partReceive } from "@/utils/api.js";
export default {
  name: "MrmrMidSearch",
  watch: {
  },
  data() {
    return {
      // 查询条件
      searchInfo:{
        tuhao:'',
        qualityNumber:'',
        transferPerson:'',
        startTime:'',
        endTime:''
      },
      resData: "",
      totalCount: 1,
      // 拒绝表单样式
      formLabelWidth: "50px",
      pageSize:10,
      pageNumber:1,
      // 接收下表的勾选数据列表
      selectList:[],
      // 归总接收数据的条码
      receiveDataList:[],
      // 归总所勾选的物料条码
      barcodeList:[],
      loginInfo:'',
      deleteTiaoma:'',
    };
  },
  methods: {
    // 零件接收-接收按钮
    partReceiveBtn(){
      if(this.selectList == ''){
        this.$Alert({
          title: "失败",
          message: '请先进行扫码移交操作',
          type: "error",
        })
      }else{
        this.loginInfo = sessionStorage.getItem("userJobNumber")
        // this.barcodeList = []          
            // data传参数据拼接
        let hcxBoxInfoList = []
        let hcxData = '';
        
        for(let i=0;i<this.selectList.length;i++){
          hcxData = {'itemCode':this.selectList[i].itemCode,'deliveryQty':this.selectList[i].deliveryQty,
                  'barcode':this.selectList[i].barcode,"wmsDeliveryPlanId":this.selectList[i].wmsDeliveryPlanId};
          hcxBoxInfoList.push(hcxData);
          this.barcodeList.push(this.selectList[i].barcode);
        }
        partReceive({
          receiveEmpCode:this.loginInfo,
          data:hcxBoxInfoList
        }).then((res)=>{
          // this.receiveDataList = []
          this.receiveDataList=this.barcodeList
          console.log(this.receiveDataList)
          if(res.data.retCode == 200){
            // 接收成功则把除该已经接收的数据的条码给下表进行删除并更新Table
            this.$bus.$emit('prDeleteTiaoma',this.receiveDataList)
            // 假传参给上表，刷新上表数据
            this.$bus.$emit('refreshPartTopTable','刷新')
            // 假传参给首页 清空条码框 聚焦
            this.$bus.$emit('rePartTmNull','')
            this.$bus.$emit('partReceJdtSuccess','完成');
            this.$Alert({
              title: "成功",
              message: res.data.message,
              type: "success"
            })
          }else {
            this.$Alert({
              title: "失败",
              message: res.data.message,
              type: "error",
            })
          }
          this.$bus.$emit('cancalMask')
          console.log('零件接收接收按钮',res,this.receiveDataList)
        })
      }
    },
    //撤销按钮
    deleteBtn(){
      for(let tr=0;tr<this.selectList.length;tr++){
        if(this.selectList[tr].barcode == this.deleteTiaoma){
          this.selectList.splice(tr,1)
        }
      }
      this.$bus.$emit('mrPrCxData',this.selectList)
      this.deleteTiaoma = ''
      this.$refs.deleteInput.focus()
    },
    // 零件接收明细---统查条件查询
    partReturnAllSearch(){
         partFinSearch({
          searchParams:{
          qualityCode:'',
          deliveryEmpCode:''
        },
        pageParameter:{
          rows:this.pageSize,
          page:1
        },
        startTime:'',
        endTime:'',                  
        drawNo:'',
      }).then((res) => {
        console.log('零件接收明细', res);
        this.$bus.$emit('preceSearchData',res.data.responseBody.result)
      });
    },
    // 条件查询按钮
    scanningSearch() {
        partFinSearch({
          searchParams:{
          qualityCode:this.searchInfo.qualityNumber,
          deliveryEmpCode:this.searchInfo.transferPerson
        },
        pageParameter:{
          rows:this.pageSize,
          page:this.pageNumber 
        },
        startTime:this.searchInfo.startTime,
        endTime:this.searchInfo.endTime,                  
        drawNo:this.searchInfo.tuhao,
      }).then((res) => {
        console.log('零件接收条件查询', res);
        // this.resData = res.data.responseBody.result;
        // this.totalCount = res.data.responseBody.pageParameter.totalCount;
        this.$bus.$emit('preceSearchData',res.data.responseBody.result)
      });
    },
  },
  mounted(){
    // 接收Tables传的pageSize，pageNumber
    this.$bus.$on('prPageNumbers',(e)=>{
      this.pageSize = e.pageSize,
      this.pageNumber = e.pageNumber
    })
    // 接收下表勾选的数据列表
    this.$bus.$on('prSelectList',(e)=>{
      this.selectList = e
    })
    // 扫码接收Input回车调用接收按钮
    this.$bus.$on('mrPrtSmReceive',(e)=>{
      // 接收
      this.$options.methods.partReceiveBtn.bind(this)()
    })
  }
};
</script>
<style scoped>
/* .el-button--warning {
  background: #ee6d4f;
  border-color: #ee6d4f;
}
.el-button--warning:hover {
  background: #c25239;
  border-color: #c25239;
} */
.mr-mr-midSearch {
  overflow: hidden;
}
.mr-mr-midSearch ul li {
  height: 35px;
  float: left;
  margin-right: 10px;
  line-height: 35px;
}
.mr-mr-midSearch ul li .el-input {
  width: 175px;
}


</style>